package com.sgb.goods.view.activity;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.sgb.goods.BR;
import com.sgb.goods.R;
import com.sgb.goods.databinding.GoodsActivityAddBrandBinding;
import com.sgb.goods.utils.Constants;
import com.sgb.goods.utils.StringUtils;
import com.sgb.goods.utils.base.BaseActivity;
import com.sgb.goods.viewmodel.AddBrandViewModel;

/**
 * 添加品牌 / 编辑品牌
 * @author cyj
 */
@Route(path = Constants.ARouter.AR_ADD_BRAND)
public class AddBrandActivity extends BaseActivity<GoodsActivityAddBrandBinding, AddBrandViewModel> {

    @Override
    protected int getLayoutResId() {
        return R.layout.goods_activity_add_brand;
    }

    @Override
    protected void initViewModel() {
        mViewModel = createViewModel(AddBrandViewModel.class, BR.viewModel);
    }

    @Override
    protected void init() {
        initView();
    }

    /** 初始化布局UI样式 */
    private void initView() {
        String id = getIntent().getStringExtra("id");
        String brandName = getIntent().getStringExtra("name");
        String remarkDesc = getIntent().getStringExtra("content");

        // 标题与内容字段填充
        mDataBinding.head.title.setText(StringUtils.isEmpty(id) ? "新增品牌" : "编辑品牌");
        mDataBinding.tvSubmit.setText(StringUtils.isEmpty(id) ? "提交" : "保存");
        mViewModel.id = id;
        mViewModel.brandName.set(StringUtils.isEmpty(brandName) ? "" : brandName);
        mViewModel.remarkDesc.set(StringUtils.isEmpty(remarkDesc) ? "" : remarkDesc);
    }

    @Override
    protected void initListener() {
        mDataBinding.head.ivBack.setOnClickListener(v -> finish());
    }
}
